package com.chengqj.blogweb.blog.web;

import com.chengqj.blogweb.blog.repo.pojo.TBlog;
import com.chengqj.blogweb.blog.repo.pojo.TBlogPhoto;
import com.chengqj.blogweb.blog.repo.pojo.TBlogRecommend;
import com.chengqj.blogweb.blog.service.IBlogService;
import com.chengqj.blogweb.blog.web.vo.QueryBlogInfoByIdResponse;
import com.chengqj.blogweb.blog.web.vo.QueryBlogInfoResponse;
import com.chengqj.blogweb.blog.web.vo.QueryBlogPhotoResponse;
import com.chengqj.blogweb.blog.web.vo.QueryBlogRecommendResponse;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: blog-web
 * @description: 博客内容web
 * @author: chengqj
 * @create: 2018-07-24 17:27
 **/
@RestController
@RequestMapping(value = "/blog")
public class BlogController {
    @Autowired
    private IBlogService blogService;
    @GetMapping(value = "/queryBlogPhotoList")
    public QueryBlogPhotoResponse queryBlogPhotoList(String type, Integer pageNum, Integer pageSize) {
        QueryBlogPhotoResponse response = new QueryBlogPhotoResponse();
        PageInfo<TBlogPhoto> blogPhotoList = blogService.selectBlogPhotoByType(type, pageNum, pageSize);
        response.setBlogPhotoList(blogPhotoList);
        return response;
    }
    @GetMapping(value = "/queryBlogInfoList")
    public QueryBlogInfoResponse queryBlogInfoList(String type, Integer pageNum, Integer pageSize) {
        QueryBlogInfoResponse response = new QueryBlogInfoResponse();
        PageInfo<TBlog> blogInfoList = blogService.selectBlogCriterion(type, pageNum, pageSize);
        response.setBlogInfoList(blogInfoList);
        return response;
    }

    @GetMapping(value = "/queryRecommendAll")
    public QueryBlogRecommendResponse selectRecommendAll() {
        List<TBlogRecommend> recommendList = blogService.selectRecommendAll();
        QueryBlogRecommendResponse response = new QueryBlogRecommendResponse();
        response.setRecommendList(recommendList);
        return response;
    }

    @GetMapping(value = "/queryBlogInfoById/{id}")
    public QueryBlogInfoByIdResponse queryBlogInfoById(@PathVariable Integer id) {
        QueryBlogInfoByIdResponse response = new QueryBlogInfoByIdResponse();
        TBlog blog = blogService.selectBlogById(id);
        response.setBlogContext(blog.getContext());
        return response;
    }

}
